<?php

namespace IDock\Insurance\ACIC\Request\NonCar;

use IDock\Insurance\ACIC\Request\AllACICRequest;
use IDock\Insurance\ACIC\Response\NonCar\NonCarRegisterResponse;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;
use IDock\Visitor\NonCar\NonCarInquiryVisitor;
use IDock\Visitor\NonCar\NonCarProductVisitor;

class NonCarRegisterRequest extends AllACICRequest
{
    protected $code = 'Q51';

    protected $response = NonCarRegisterResponse::class;

    protected $urlTip = '车搭非中 非车详细信息登记接口';

    //public $isNonCar = true;

    public $appNo;

    public $beginDate;

    public $endDate;

    public $premium;

    public $biInquiryNo;

    public $ciInquiryNo;

    private $coverage;

    public function coverage(NonCarInquiryVisitor $nonCarInquiryVisitor)
    {
        $list = [];

        foreach ($nonCarInquiryVisitor->getNonCarList() as $nonCarList) {
            /*** @var NonCarProductVisitor $nonCarList */
            foreach ($nonCarList->subCoverage as $item) {
                /*** @var NonCarSubCoveragePrinter $item */
                $list[] = [
                    'CvrgNo' => $item->subCode,
                    'Sumlimit' => $item->amount,
                    'Premium' => $item->premium,
                    'Remark' => ''
                ];
            }
        }
        $this->coverage['Cvrg'] = $list;
    }

    public function generate(): array
    {
        return [
            'AppNo' => $this->appNo,
            'SpecialDesc' => '',
            'Type' => '007001',
            'TypeDesc' => '',
            'BegDate' => $this->beginDate,
            'EndDate' => $this->endDate,
            'NvhlPremium' => $this->premium,
            'TotalSumlimit' => '',
            'TotalPremium' => '',
            'CvrgList' => $this->coverage,
            'VhlAppNo' => $this->biInquiryNo ?: $this->ciInquiryNo,
        ];
    }
}
